
import os
import qianfan



class  AI:
        
      def __init__(self):

        #【推荐】使用安全认证AK/SK鉴权，通过环境变量初始化认证信息
        # 替换下列示例中参数，安全认证Access Key替换your_iam_ak，Secret Key替换your_iam_sk
        os.environ["QIANFAN_ACCESS_KEY"] = "ALTAKpclaKcJrZW6guVb9rCfqb"
        os.environ["QIANFAN_SECRET_KEY"] = "d1c14aee281f449aa12de01fc815aa5d"

        self.chat_comp = qianfan.ChatCompletion()

      def AIReply(self,problem):
        problem = str(problem)
        # print("SDK接受了：",problem)
        # 指定特定模型
        resp = self.chat_comp.do(model="ERNIE-4.0-8K", messages=[{
                "role": "user",
                "content": problem
        }])
        resp1= resp["body"]['result']
        resp2 = str(resp1).strip()              #转成string并去空格
        return resp2.split('\n')    #切片